<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:zj="http://www.zju.edu.cn" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="msxsl">
  <xsl:param name="DataXml"/>
  <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>
  <xsl:variable name="zj:Relations" select="/Toolkit/zj:Module/zj:Relations/zj:Relation"/>
  <xsl:variable name="zj:Resolvers" select="/Toolkit/zj:Module/zj:Resolvers/zj:Resolver"/>
  <xsl:variable name="zj:Module" select="/Toolkit"/>
  <xsl:template match="/">
    <xsl:variable name="zj:AllXmlData">
      <xsl:apply-templates select="Toolkit/zj:Module/zj:Resolvers/zj:Resolver[(@Style != 'None') and (not(@Type) or @Type != 'View')]" mode="zj:RawData"/>
    </xsl:variable>
    <xsl:variable name="zj:AllXmlNodeSet" select="msxsl:node-set($zj:AllXmlData)/zj:Table"/>
    <Toolkit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zj="http://www.zju.edu.cn" Desc="{Toolkit/zj:Module/zj:Title}" Module="{Toolkit/zj:Module/zj:DataSet}">
      <xsl:attribute name="Tables"><xsl:apply-templates select="$zj:AllXmlNodeSet" mode="zj:Table"/></xsl:attribute>
      <xsl:attribute name="Fields"><xsl:apply-templates select="$zj:AllXmlNodeSet" mode="zj:Field"/></xsl:attribute>
      <xsl:call-template name="ModuleNode"/>
      <xsl:apply-templates select="$zj:AllXmlNodeSet" mode="zj:Data"/>
      <xsl:apply-templates select="$zj:AllXmlNodeSet" mode="zj:RefJS"/>
    </Toolkit>
  </xsl:template>
  <xsl:template name="ModuleNode">
    <xsl:if test="count(Toolkit/zj:Module/zj:Extension) > 0">
      <xsl:copy-of select="Toolkit/zj:Module/zj:Extension"/>
    </xsl:if>
    <xsl:if test="count(Toolkit/zj:Module/zj:DisablePage) > 0">
      <zj:DisablePage>
        <xsl:if test="contains(Toolkit/zj:Module/zj:DisablePage, 'List')">
          <List/>
        </xsl:if>
        <xsl:if test="contains(Toolkit/zj:Module/zj:DisablePage, 'Detail')">
          <Detail/>
        </xsl:if>
        <xsl:if test="contains(Toolkit/zj:Module/zj:DisablePage, 'Insert')">
          <Insert/>
        </xsl:if>
        <xsl:if test="contains(Toolkit/zj:Module/zj:DisablePage, 'Update')">
          <Update/>
        </xsl:if>
        <xsl:if test="contains(Toolkit/zj:Module/zj:DisablePage, 'Delete')">
          <Delete/>
        </xsl:if>
      </zj:DisablePage>
    </xsl:if>
  </xsl:template>
  <xsl:template match="zj:Resolver" mode="zj:RawData">
    <xsl:choose>
      <xsl:when test="boolean($DataXml)">
        <xsl:call-template name="PaserXml">
          <xsl:with-param name="nodes" select="."></xsl:with-param>
          <xsl:with-param name="doc" select="$DataXml/Toolkit/zj:Table"></xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="PaserXml">
          <xsl:with-param name="nodes" select="."></xsl:with-param>
          <xsl:with-param name="doc" select="document(zj:Xml)/Toolkit/zj:Table"></xsl:with-param>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template name="PaserXml">
    <xsl:param name="nodes"></xsl:param>
    <xsl:param name ="doc"></xsl:param>
    <xsl:variable name="TableName">
      <xsl:choose>
        <xsl:when test="@TableName">
          <xsl:value-of select="@TableName"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$doc/@TableName"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="TableDesc">
      <xsl:choose>
        <xsl:when test="@TableDesc">
          <xsl:value-of select="@TableDesc"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$doc/@TableDesc"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="NewTable">
      <zj:Table TableName="{$TableName}" TableDesc="{$TableDesc}" Style="{@Style}" SrcTableName="{$doc/@TableName}" KeyCount="{count($doc/zj:Field[boolean(@IsKey='true')])}" RegName="{zj:RegName}" XmlFile="{zj:Xml}">
        <xsl:attribute name="Expand"><xsl:choose><xsl:when test="@Expand='false'">false</xsl:when><xsl:otherwise>true</xsl:otherwise></xsl:choose></xsl:attribute>
        <xsl:call-template name="zj:SetNewTableData">
          <xsl:with-param name="ResolverData" select="."/>
          <xsl:with-param name="TableData" select="$doc"/>
        </xsl:call-template>
        <xsl:copy-of select="zj:ListRefParams"/>
      </zj:Table>
    </xsl:variable>
    <xsl:apply-templates select="msxsl:node-set($NewTable)/zj:Table" mode="zj:RawData"/>
  </xsl:template>
  
  <xsl:template match="zj:Field" mode="zj:RawData">
    <xsl:param name="OverrideInfo"/>
    <xsl:param name="Fields"/>
    <xsl:variable name="FieldName" select="zj:FieldName"/>
    <xsl:choose>
      <xsl:when test="$OverrideInfo/Except/DelField[@FieldName=$FieldName]"/>
      <xsl:when test="$Fields/zj:Upload/@ServerPathField=$FieldName or $Fields/zj:Upload/@ContentField=$FieldName or $Fields/zj:Upload/@MimeTypeField=$FieldName or $Fields/zj:Upload/@SizeField=$FieldName"/>
      <xsl:otherwise>
        <xsl:call-template name="DefaultRavData">
          <xsl:with-param name="OverrideInfo" select="$OverrideInfo"/>
          <xsl:with-param name="Fields" select="$Fields"/>
          <xsl:with-param name="FieldName" select="$FieldName"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="DefaultRavData">
    <xsl:param name="OverrideInfo"/>
    <xsl:param name="Fields"/>
    <xsl:param name="FieldName"/>
    <xsl:variable name="zj:Override" select="$OverrideInfo/Override/Field"/>
    <xsl:variable name="zj:Except" select="$OverrideInfo/Except/DelField"/>
    <xsl:variable name="FieldOverride" select="$zj:Override[@FieldName=$FieldName]"/>
    <xsl:variable name="FieldHtmlCtrl">
      <xsl:choose>
        <xsl:when test="$FieldOverride/@HtmlCtrl">
          <xsl:value-of select="$FieldOverride/@HtmlCtrl"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="zj:HtmlCtrl/@HtmlCtrl"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="RealHtmlCtrl">
      <xsl:apply-templates select="." mode="zj:HtmlCtrl">
        <xsl:with-param name="HtmlCtrl" select="$FieldHtmlCtrl"/>
        <xsl:with-param name="Style" select="../@Style"/>
      </xsl:apply-templates>
    </xsl:variable>
    <xsl:if test="$RealHtmlCtrl != ''">
      <zj:Field>
        <xsl:copy-of select="@*"/>
        <xsl:if test="$FieldOverride/@IsEmpty">
          <xsl:attribute name="IsEmpty"><xsl:value-of select="$FieldOverride/@IsEmpty"/></xsl:attribute>
        </xsl:if>
        <xsl:if test="not(@Kind)">
          <xsl:attribute name="Kind">Data</xsl:attribute>
        </xsl:if>
        <xsl:copy-of select="zj:FieldName"/>
        <zj:DisplayName>
          <xsl:choose>
            <xsl:when test="$FieldOverride/@DisplayName">
              <xsl:value-of select="$FieldOverride/@DisplayName"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="zj:DisplayName"/>
            </xsl:otherwise>
          </xsl:choose>
        </zj:DisplayName>
        <xsl:variable name="Hint">
          <xsl:choose>
            <xsl:when test="$FieldOverride/@Hint">
              <xsl:value-of select="$FieldOverride/@Hint"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="zj:Hint"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:if test="$Hint != ''">
          <zj:Hint>
            <xsl:value-of select="$Hint"/>
          </zj:Hint>
        </xsl:if>
        <xsl:copy-of select="zj:Length"/>
        <xsl:variable name="CodeTable">
          <xsl:choose>
            <xsl:when test="$FieldOverride/@CodeTable">
              <xsl:value-of select="$FieldOverride/@CodeTable"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="zj:CodeTable"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:if test="$CodeTable != ''">
          <zj:CodeTable>
            <xsl:value-of select="$CodeTable"/>
          </zj:CodeTable>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="$FieldOverride/@EasySearch">
            <zj:EasySearch RegName="{$FieldOverride/@EasySearch}">
              <xsl:copy-of select="zj:EasySearch/*"/>
            </zj:EasySearch>
          </xsl:when>
          <xsl:otherwise>
            <xsl:copy-of select="zj:EasySearch"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:variable name="ReadOnly">
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@ReadOnly">
              <xsl:value-of select="$FieldOverride/Display/@ReadOnly"/>
            </xsl:when>
            <xsl:when test="zj:Display/@ReadOnly">
              <xsl:value-of select="zj:Display/@ReadOnly"/>
            </xsl:when>
            <xsl:otherwise>false</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <zj:Display>
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@Format">
              <xsl:attribute name="Format"><xsl:value-of select="$FieldOverride/Display/@Format"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="zj:Display/@Format"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@ThreeColumn">
              <xsl:attribute name="ThreeColumn"><xsl:value-of select="$FieldOverride/Display/@ThreeColumn"/></xsl:attribute>
            </xsl:when>
            <xsl:when test="zj:Display/@ThreeColumn">
              <xsl:attribute name="ThreeColumn"><xsl:value-of select="zj:Display/@ThreeColumn"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="ThreeColumn">three</xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@ListRef">
              <xsl:attribute name="ListRef"><xsl:value-of select="$FieldOverride/Display/@ListRef"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="zj:Display/@ListRef"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@ListWidth">
              <xsl:attribute name="ListWidth"><xsl:value-of select="$FieldOverride/Display/@ListWidth"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="zj:Display/@ListWidth"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@Align">
              <xsl:attribute name="Align"><xsl:value-of select="$FieldOverride/Display/@Align"/></xsl:attribute>
            </xsl:when>
            <xsl:when test="zj:Display/@Align">
              <xsl:attribute name="Align"><xsl:value-of select="zj:Display/@Align"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="Align">left</xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="$FieldOverride/Display/@TextHead">
              <xsl:attribute name="TextHead"><xsl:value-of select="$FieldOverride/Display/@TextHead"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="zj:Display/@TextHead"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:if test="zj:Display/Link or $FieldOverride/Display/Link">
            <xsl:choose>
              <xsl:when test="$FieldOverride/Display/Link">
                <xsl:copy-of select="$FieldOverride/Display/Link"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:copy-of select="zj:Display/Link"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
          <xsl:variable name="OverrideAttr" select="$FieldOverride/Display/Attribute"/>
          <xsl:copy-of select="$OverrideAttr"/>
          <xsl:for-each select="zj:Display/Attribute">
            <xsl:if test="not($OverrideAttr/@Name=@Name)">
              <xsl:copy-of select="."/>
            </xsl:if>
          </xsl:for-each>
          <xsl:if test="$ReadOnly='true'">
            <xsl:choose>
              <xsl:when test="$RealHtmlCtrl='Combo' or $RealHtmlCtrl='MultiSelect'">
                <Attribute Name="disabled" Value="disabled"/>
              </xsl:when>
              <xsl:when test="$RealHtmlCtrl='Text' or $RealHtmlCtrl='Radio' or $RealHtmlCtrl='TextArea' or $RealHtmlCtrl='CheckBox' or $RealHtmlCtrl='EasySearch' or $RealHtmlCtrl='Password' or $RealHtmlCtrl='File'or $RealHtmlCtrl='CheckBoxList'">
                <Attribute Name="readonly" Value="readonly"/>
              </xsl:when>
            </xsl:choose>
          </xsl:if>
        </zj:Display>
        <xsl:if test="zj:Extension or $FieldOverride/Extension">
          <zj:Extension>
            <xsl:copy-of select="zj:Extension/@ImgClick"/>
            <xsl:copy-of select="zj:Extension/@Span"/>
            <xsl:copy-of select="zj:Extension/@SortField"/>
            <xsl:copy-of select="zj:Extension/@EmptyTitle"/>
            <xsl:copy-of select="zj:Extension/@Expression"/>
            <xsl:choose>
              <xsl:when test="zj:Extension/@CheckValue">
                <xsl:copy-of select="zj:Extension/@CheckValue"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:if test="$RealHtmlCtrl='CheckBox'">
                  <xsl:attribute name="CheckValue">1</xsl:attribute>
                </xsl:if>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
              <xsl:when test="zj:Extension/@UnCheckValue">
                <xsl:copy-of select="zj:Extension/@UnCheckValue"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:if test="$RealHtmlCtrl='CheckBox'">
                  <xsl:attribute name="UnCheckValue">0</xsl:attribute>
                </xsl:if>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
              <xsl:when test="$FieldOverride/Extension/@Search">
                <xsl:if test="$FieldOverride/Extension/@Search='title'">
                  <xsl:attribute name="Search">title</xsl:attribute>
                </xsl:if>
              </xsl:when>
              <xsl:otherwise>
                <xsl:copy-of select="zj:Extension/@Search"/>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="$FieldOverride/Extension/@ImgClick">
              <xsl:attribute name="ImgClick"><xsl:value-of select="$FieldOverride/Extension/@ImgClick"/></xsl:attribute>
            </xsl:if>
            <xsl:if test="$FieldOverride/Extension/@Span">
              <xsl:attribute name="Span"><xsl:value-of select="$FieldOverride/Extension/@Span"/></xsl:attribute>
            </xsl:if>
            <xsl:if test="$FieldOverride/Extension/@CheckValue">
              <xsl:attribute name="CheckValue"><xsl:value-of select="$FieldOverride/Extension/@CheckValue"/></xsl:attribute>
            </xsl:if>
            <xsl:if test="$FieldOverride/Extension/@Expression">
              <xsl:attribute name="Expression"><xsl:value-of select="$FieldOverride/Extension/@Expression"/></xsl:attribute>
            </xsl:if>
            <xsl:copy-of select="zj:Extension/*"/>
          </zj:Extension>
        </xsl:if>
        <zj:HtmlCtrl>
          <xsl:copy-of select="zj:HtmlCtrl/@*"/>
          <xsl:attribute name="HtmlCtrl"><xsl:value-of select="$RealHtmlCtrl"/></xsl:attribute>
          <xsl:if test="$FieldOverride/@Order">
            <xsl:attribute name="Order"><xsl:value-of select="$FieldOverride/@Order"/></xsl:attribute>
          </xsl:if>
          <xsl:copy-of select="zj:HtmlCtrl/*"/>
        </zj:HtmlCtrl>
        <xsl:choose>
          <xsl:when test="$FieldOverride/DefaultValue">
            <zj:DefaultValue>
              <xsl:copy-of select="$FieldOverride/DefaultValue/@*"/>
              <xsl:copy-of select="$FieldOverride/DefaultValue"/>
            </zj:DefaultValue>
          </xsl:when>
          <xsl:otherwise>
            <xsl:copy-of select="zj:DefaultValue"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:copy-of select="zj:Updating"/>
        <xsl:copy-of select="zj:Upload"/>
      </zj:Field>
    </xsl:if>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:RawData">
    <xsl:variable name="SortData">
      <xsl:for-each select="zj:Field">
        <xsl:sort select="zj:HtmlCtrl/@Order" data-type="number"/>
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </xsl:variable>
    <zj:Table>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="$SortData"/>
      <xsl:copy-of select="zj:ListRefParams"/>
    </zj:Table>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:Data">
    <xsl:variable name="RegName" select="@RegName"/>
    <zj:Table>
      <xsl:copy-of select="@*"/>
      <Hidden>
        <xsl:apply-templates select="zj:Field[zj:HtmlCtrl/@HtmlCtrl='Hidden']" mode="zj:Data"/>
      </Hidden>
      <xsl:variable name="DisplayFields" select="zj:Field[zj:HtmlCtrl/@HtmlCtrl!='Hidden']"/>
      <xsl:choose>
        <xsl:when test="@Style='Normal'">
          <xsl:call-template name="zj:Display">
            <xsl:with-param name="Data" select="$DisplayFields"/>
            <xsl:with-param name="Pos" select="1"/>
            <xsl:with-param name="Count" select="count($DisplayFields)"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="@Style='Table'">
          <List>
            <xsl:apply-templates select="$DisplayFields" mode="zj:Data"/>
          </List>
        </xsl:when>
      </xsl:choose>
      <xsl:variable name="Resolver" select="$zj:Resolvers[zj:RegName=$RegName]"/>
      <xsl:variable name="Relation" select="$zj:Relations[zj:DetailResolver=$RegName]"/>
      <xsl:variable name="Tables" select="following-sibling::zj:Table | preceding-sibling::zj:Table"/>
      <xsl:call-template name="zj:ListRefParams">
        <xsl:with-param name="Resolver" select="$Resolver"/>
        <xsl:with-param name="Relation" select="$Relation"/>
        <xsl:with-param name="Tables" select="$Tables"/>
      </xsl:call-template>
      <xsl:copy-of select="zj:ListRefParams"/>
    </zj:Table>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:Data">
    <xsl:variable name="FieldName" select="zj:FieldName"/>
    <xsl:variable name="Ref">
      <xsl:call-template name="zj:EasySearchRef">
        <xsl:with-param name="Field" select="."/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="HtmlCtrl" select="zj:HtmlCtrl/@HtmlCtrl"/>
    <zj:Field>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="zj:FieldName"/>
      <xsl:copy-of select="zj:DisplayName"/>
      <xsl:copy-of select="zj:Hint"/>
      <xsl:copy-of select="zj:Length"/>
      <xsl:copy-of select="zj:CodeTable"/>
      <xsl:copy-of select="zj:EasySearch"/>
      <zj:Display>
        <xsl:copy-of select="zj:Display/@*"/>
        <xsl:if test="zj:Display/Link">
          <xsl:variable name="RefType">
            <xsl:call-template name="zj:HRefType">
              <xsl:with-param name="Link" select="zj:Display/Link"/>
            </xsl:call-template>
          </xsl:variable>
          <Link HRefType="{$RefType}">
            <xsl:copy-of select="zj:Display/Link/@*"/>
            <xsl:value-of select="zj:Display/Link"/>
          </Link>
        </xsl:if>
        <xsl:if test="zj:Hint">
          <Attribute Name="title" Value="{zj:Hint}"/>
        </xsl:if>
        <xsl:variable name="RefBy" select="(following-sibling::zj:Field | preceding-sibling::zj:Field)[zj:EasySearch/RefValue/@RefField=$FieldName]"/>
        <xsl:if test="$RefBy">
          <Attribute Name="onchange" Value="{$FieldName}_change()"/>
        </xsl:if>
        <xsl:variable name="ReadOnly" select="zj:Display/@ReadOnly='true'"/>
        <xsl:choose>
          <xsl:when test="@DataType='Date' and $HtmlCtrl='Text' and not($ReadOnly)">
            <Attribute Name="maxlength" Value="10"/>
          </xsl:when>
          <xsl:when test="@DataType='DateTime' and $HtmlCtrl='Text' and not($ReadOnly)">
            <Attribute Name="maxlength" Value="19"/>
          </xsl:when>
          <xsl:when test="$HtmlCtrl='EasySearch' and not($ReadOnly)">
            <xsl:variable name="FastSearchParams" select="concat('document.all(&quot;hd', $FieldName, 'Type&quot;, GetRowID(this)).value, this.value, document.all(&quot;hd', $FieldName, '&quot;, GetRowID(this))', $Ref)"/>
            <Attribute Name="onkeydown" Value="if (event.keyCode == 9) DocOnClick();"/>
            <Attribute Name="onlosecapture" Value="floatdivflag = 1"/>
            <Attribute Name="onkeyup" Value="FastSearch({$FastSearchParams})"/>
            <Attribute Name="onfocus" Value="FastSearch2({$FastSearchParams})"/>
          </xsl:when>
          <xsl:when test="$HtmlCtrl='CheckBox'">
            <Attribute Name="style" Value="border:0"/>
          </xsl:when>
          <xsl:when test="$HtmlCtrl='Text' or $HtmlCtrl='TextArea'">
            <xsl:if test="zj:Length!=0">
              <Attribute Name="maxlength" Value="{zj:Length}"/>
            </xsl:if>
          </xsl:when>
        </xsl:choose>
        <xsl:copy-of select="zj:Display/Attribute"/>
      </zj:Display>
      <zj:Extension>
        <xsl:copy-of select="zj:Extension/@*"/>
        <xsl:if test="not(@ImgClick) and $HtmlCtrl='EasySearch'">
          <xsl:attribute name="ImgClick">openLookup1('../Pages/WebDialogSearch2Page.zjx?IdElementName=hd<xsl:value-of select="$FieldName"/>&amp;EditElementName=<xsl:value-of select="$FieldName"/>'<xsl:value-of select="$Ref"/>)</xsl:attribute>
        </xsl:if>
        <xsl:copy-of select="zj:Extension/*"/>
      </zj:Extension>
      <xsl:copy-of select="zj:HtmlCtrl"/>
      <xsl:copy-of select="zj:DefaultValue"/>
      <xsl:copy-of select="zj:Updating"/>
      <xsl:copy-of select="zj:Upload"/>
    </zj:Field>
  </xsl:template>
  <xsl:template name="zj:AddRawField">
    <xsl:param name="OverrideInfo"/>
    <xsl:variable name="AddFields" select="$OverrideInfo/Add/AddField"/>
    <xsl:for-each select="$AddFields">
      <zj:Field DataType="{@DataType}" Kind="{@Kind}">
        <xsl:if test="@IsEmpty">
          <xsl:attribute name="IsEmpty"><xsl:value-of select="@IsEmpty"/></xsl:attribute>
        </xsl:if>
        <zj:FieldName>
          <xsl:value-of select="@FieldName"/>
        </zj:FieldName>
        <zj:DisplayName>
          <xsl:value-of select="@DisplayName"/>
        </zj:DisplayName>
        <xsl:if test="@Hint">
          <zj:Hint>
            <xsl:value-of select="@Hint"/>
          </zj:Hint>
        </xsl:if>
        <xsl:if test="@Length">
          <zj:Length>
            <xsl:value-of select="@Length"/>
          </zj:Length>
        </xsl:if>
        <xsl:if test="@CodeTable">
          <zj:CodeTable>
            <xsl:value-of select="@CodeTable"/>
          </zj:CodeTable>
        </xsl:if>
        <xsl:if test="EasySearch">
          <zj:EasySearch>
            <xsl:copy-of select="EasySearch/@*"/>
            <xsl:copy-of select="EasySearch/*"/>
          </zj:EasySearch>
        </xsl:if>
        <xsl:if test="Display">
          <zj:Display>
            <xsl:copy-of select="Display/@*"/>
            <xsl:attribute name="TextHead">fasle</xsl:attribute>
            <xsl:copy-of select="Display/*"/>
          </zj:Display>
        </xsl:if>
        <xsl:if test="Extension">
          <zj:Extension>
            <xsl:copy-of select="Extension/@*"/>
            <xsl:copy-of select="Extension/*"/>
          </zj:Extension>
        </xsl:if>
        <zj:HtmlCtrl HtmlCtrl="{@HtmlCtrl}" Order="{@Order}"/>
        <xsl:if test="DefaultValue">
          <zj:DefaultValue>
            <xsl:copy-of select="DefaultValue/@*"/>
            <xsl:copy-of select="DefaultValue"/>
          </zj:DefaultValue>
        </xsl:if>
      </zj:Field>
    </xsl:for-each>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:RefJS">
    <xsl:variable name="FieldList" select="zj:Field"/>
    <xsl:variable name="RefJS">
      <xsl:apply-templates select="zj:Field[zj:HtmlCtrl/@HtmlCtrl='Combo' or zj:HtmlCtrl/@HtmlCtrl='EasySearch']" mode="zj:RefJS">
        <xsl:with-param name="FieldList" select="$FieldList"/>
      </xsl:apply-templates>
    </xsl:variable>
    <xsl:if test="$RefJS != ''">
      <zj:RefJS>
        <xsl:value-of select="$RefJS"/>
      </zj:RefJS>
    </xsl:if>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:RefJS">
    <xsl:param name="FieldList"/>
    <xsl:call-template name="zj:EasySearchRefBy">
      <xsl:with-param name="Field" select="."/>
      <xsl:with-param name="FieldList" select="$FieldList"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="zj:OneColumn">
    <xsl:param name="Data"/>
    <xsl:param name="Pos"/>
    <xsl:param name="Count"/>
    <xsl:param name="CurNode"/>
    <Row FieldName="{$CurNode/zj:FieldName}">
      <xsl:apply-templates select="$CurNode" mode="zj:Data"/>
    </Row>
    <xsl:call-template name="zj:Display">
      <xsl:with-param name="Data" select="$Data"/>
      <xsl:with-param name="Pos" select="$Pos + 1"/>
      <xsl:with-param name="Count" select="$Count"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="zj:TwoColumn">
    <xsl:param name="Data"/>
    <xsl:param name="Pos"/>
    <xsl:param name="Count"/>
    <xsl:param name="CurNode"/>
    <xsl:param name="NextNode"/>
    <Row FieldName="{$CurNode/zj:FieldName}">
      <xsl:apply-templates select="$CurNode" mode="zj:Data"/>
      <xsl:apply-templates select="$NextNode" mode="zj:Data"/>
    </Row>
    <xsl:call-template name="zj:Display">
      <xsl:with-param name="Data" select="$Data"/>
      <xsl:with-param name="Pos" select="$Pos + 2"/>
      <xsl:with-param name="Count" select="$Count"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="zj:ThreeColumn">
    <xsl:param name="Data"/>
    <xsl:param name="Pos"/>
    <xsl:param name="Count"/>
    <xsl:param name="CurNode"/>
    <xsl:param name="NextNode"/>
    <xsl:param name="ThirdNode"/>
    <Row FieldName="{$CurNode/zj:FieldName}">
      <xsl:apply-templates select="$CurNode" mode="zj:Data"/>
      <xsl:apply-templates select="$NextNode" mode="zj:Data"/>
      <xsl:apply-templates select="$ThirdNode" mode="zj:Data"/>
    </Row>
    <xsl:call-template name="zj:Display">
      <xsl:with-param name="Data" select="$Data"/>
      <xsl:with-param name="Pos" select="$Pos + 3"/>
      <xsl:with-param name="Count" select="$Count"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="zj:Display">
    <xsl:param name="Data"/>
    <xsl:param name="Pos"/>
    <xsl:param name="Count"/>
    <xsl:if test="$Pos &lt;= $Count">
      <xsl:variable name="CurNode" select="$Data[$Pos]"/>
      <xsl:variable name="ThreeColumn" select="$CurNode/zj:Display/@ThreeColumn"/>
      <xsl:choose>
        <xsl:when test="$ThreeColumn = 'one'">
          <xsl:call-template name="zj:OneColumn">
            <xsl:with-param name="Data" select="$Data"/>
            <xsl:with-param name="Pos" select="$Pos"/>
            <xsl:with-param name="Count" select="$Count"/>
            <xsl:with-param name="CurNode" select="$CurNode"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="$ThreeColumn = 'two'">
          <xsl:variable name="NextNode" select="$Data[$Pos + 1]"/>
          <xsl:variable name="NextThreeColumn" select="$NextNode/zj:Display/@ThreeColumn"/>
          <xsl:choose>
            <xsl:when test="$NextThreeColumn='three' or $NextThreeColumn=''">
              <xsl:call-template name="zj:TwoColumn">
                <xsl:with-param name="Data" select="$Data"/>
                <xsl:with-param name="Pos" select="$Pos"/>
                <xsl:with-param name="Count" select="$Count"/>
                <xsl:with-param name="CurNode" select="$CurNode"/>
                <xsl:with-param name="NextNode" select="$NextNode"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="zj:OneColumn">
                <xsl:with-param name="Data" select="$Data"/>
                <xsl:with-param name="Pos" select="$Pos"/>
                <xsl:with-param name="Count" select="$Count"/>
                <xsl:with-param name="CurNode" select="$CurNode"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="NextNode" select="$Data[$Pos + 1]"/>
          <xsl:variable name="NextThreeColumn" select="$NextNode/zj:Display/@ThreeColumn"/>
          <xsl:choose>
            <xsl:when test="$NextThreeColumn='one'">
              <xsl:call-template name="zj:OneColumn">
                <xsl:with-param name="Data" select="$Data"/>
                <xsl:with-param name="Pos" select="$Pos"/>
                <xsl:with-param name="Count" select="$Count"/>
                <xsl:with-param name="CurNode" select="$CurNode"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:when test="$NextThreeColumn='two'">
              <xsl:call-template name="zj:TwoColumn">
                <xsl:with-param name="Data" select="$Data"/>
                <xsl:with-param name="Pos" select="$Pos"/>
                <xsl:with-param name="Count" select="$Count"/>
                <xsl:with-param name="CurNode" select="$CurNode"/>
                <xsl:with-param name="NextNode" select="$NextNode"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:variable name="ThirdNode" select="$Data[$Pos + 2]"/>
              <xsl:variable name="ThirdThreeColumn" select="$ThirdNode/zj:Display/@ThreeColumn"/>
              <xsl:choose>
                <xsl:when test="$ThirdThreeColumn='one' or $ThirdThreeColumn='two'">
                  <xsl:call-template name="zj:TwoColumn">
                    <xsl:with-param name="Data" select="$Data"/>
                    <xsl:with-param name="Pos" select="$Pos"/>
                    <xsl:with-param name="Count" select="$Count"/>
                    <xsl:with-param name="CurNode" select="$CurNode"/>
                    <xsl:with-param name="NextNode" select="$NextNode"/>
                  </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:call-template name="zj:ThreeColumn">
                    <xsl:with-param name="Data" select="$Data"/>
                    <xsl:with-param name="Pos" select="$Pos"/>
                    <xsl:with-param name="Count" select="$Count"/>
                    <xsl:with-param name="CurNode" select="$CurNode"/>
                    <xsl:with-param name="NextNode" select="$NextNode"/>
                    <xsl:with-param name="ThirdNode" select="$ThirdNode"/>
                  </xsl:call-template>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:Table">
    <xsl:if test="position() != 1">,</xsl:if>
    <xsl:value-of select="@TableName"/>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:Field">
    <xsl:if test="position() != 1">;</xsl:if>
    <xsl:apply-templates select="zj:Field[zj:HtmlCtrl/@HtmlCtrl!='Detail' and zj:HtmlCtrl/@HtmlCtrl!='DetailCheckBoxList' and zj:HtmlCtrl/@HtmlCtrl!='DetailMultiSelect']" mode="zj:Field"/>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:Field">
    <xsl:if test="position() != 1">,</xsl:if>
    <xsl:if test="@IsKey='true'">
      <xsl:value-of select="concat('OLD_', zj:FieldName, ',')"/>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="zj:HtmlCtrl/@HtmlCtrl='EasySearch'">
        <xsl:value-of select="concat('hd', zj:FieldName, ',', zj:FieldName)"/>
      </xsl:when>
      <xsl:when test="zj:HtmlCtrl/@HtmlCtrl='Upload'">
        <xsl:value-of select="concat(zj:FieldName, ',', zj:Upload/@ServerPathField)"/>
        <xsl:if test="zj:Upload/@MimeTypeField != ''">
          <xsl:value-of select="concat(',', zj:Upload/@MimeTypeField)"/>
        </xsl:if>
        <xsl:if test="zj:Upload/@SizeField != ''">
          <xsl:value-of select="concat(',', zj:Upload/@SizeField)"/>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="zj:FieldName"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="zj:SetNewTableData">
    <xsl:param name="ResolverData"/>
    <xsl:param name="TableData"/>
  </xsl:template>
  <xsl:template name="zj:ListRefParams">
    <xsl:param name="Resolver"/>
    <xsl:param name="Relation"/>
    <xsl:param name="Tables"/>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:HtmlCtrl">
    <xsl:param name="HtmlCtrl"/>
    <xsl:param name="Style"/>
    <xsl:value-of select="$HtmlCtrl"/>
  </xsl:template>
  <xsl:template name="zj:EasySearchRef">
    <xsl:param name="Field"/>
    <xsl:for-each select="$Field/zj:EasySearch/RefValue">
      <xsl:value-of select="concat(', &quot;', @Field, '&quot;, ')"/>
      <xsl:variable name="RefFieldName" select="@RefField"/>
      <xsl:for-each select="$Field">
        <xsl:variable name="RefField" select="(following-sibling::zj:Field | preceding-sibling::zj:Field)[zj:FieldName=$RefFieldName]"/>
        <xsl:choose>
          <xsl:when test="$RefField/zj:EasySearch">"hd<xsl:value-of select="$RefField/zj:FieldName"/>"</xsl:when>
          <xsl:otherwise>"<xsl:value-of select="$RefField/zj:FieldName"/>"</xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="zj:EasySearchRefBy">
    <xsl:param name="Field"/>
    <xsl:param name="FieldList"/>
    <xsl:variable name="Temp" select="$FieldList[zj:EasySearch/RefValue/@RefField=$Field/zj:FieldName]"/>
    <xsl:if test="boolean($Temp)">
       function <xsl:value-of select="$Field/zj:FieldName"/>_change(){
         var eleObj = window.event.srcElement;
         var pos = GetRowID(eleObj);
         <xsl:for-each select="$Temp">document.all("<xsl:value-of select="zj:FieldName"/>", pos).value = "";</xsl:for-each>
       }</xsl:if>
  </xsl:template>
  <xsl:template name="zj:HRefType">
    <xsl:param name="Link"/>
    <xsl:choose>
      <xsl:when test="translate($Link,'htp','HTP') = 'HTTP'">HTTP</xsl:when>
      <xsl:when test="translate($Link,'email','EMAIL')='EMAIL'">EMAIL</xsl:when>
      <xsl:when test="$Link != ''">HREF</xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
